package org.spring.boot.sample.activemq;

import javax.jms.Queue;
import javax.jms.Topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

@Component
public class ProducerService implements CommandLineRunner{

	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;

	@Autowired
	private Queue queue;
	
	@Autowired
	private Topic topic;
	
	@Scheduled(fixedRate = 3000)
	public void run(String... args) throws Exception {
		//sendQueue("hi, ActiveMQ");
		//sendTopic("hi,ActiveMQ(topic)");
	}
	
	public void sendQueue(String msg){
		this.jmsMessagingTemplate.convertAndSend(this.queue, msg);
	}
	
	public void sendTopic(String msg){
		this.jmsMessagingTemplate.convertAndSend(this.topic, msg);
	}
}
